package com.fz.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JdbcUtils {
    public static  int update(String sql) throws  Exception{
        String url="jdbc:mysql://localhost:3306/test";
        String username="root";
        String password="root";
        try{
            Class.forName("com.mysql.jdbc.Driver");
            Connection connection = DriverManager.getConnection(url,username,password);
            Statement statement = connection.createStatement();
            return statement.executeUpdate(sql);
        }catch (Exception e){
            e.printStackTrace();
        }
        return 0;
    }

     public static void select(String sql) throws  Exception {
         String url = "jdbc:mysql://localhost:3306/test";
         String username = "root";
         String password = "root";
         try {
             Class.forName("com.mysql.jdbc.Driver");
             Connection connection = DriverManager.getConnection(url, username, password);
             Statement statement = connection.createStatement();
             ResultSet set = statement.executeQuery(sql);
             while (set.next()) {
                 String c1 = set.getString(1);
                 System.out.println("c1=" + c1);
             }
         } catch (Exception e) {
             e.printStackTrace();
         }
     }

     }
